import random 
import string

def GeneratePWD(length):
    #1位数字
    num_Num = 1
    #1位特殊字符
    num_Spe = 1    
    #剩余字符个数    
    num_Letter = length - num_Num - num_Spe
    #随机出大写字母个数
    num_UPLetter = random.randint(0,num_Letter)
    #print num_UPLetter
    #剩余小写字母个数
    num_LOWLetter = num_Letter-num_UPLetter
    #print num_LOWLetter
    #随机选择1个数字
    Num = [random.choice(string.digits) for i in range(num_Num)]
    #随机选择1个特殊字符
    Spe = [random.choice('!@#$%^&*()><?') for i in range(num_Spe)]
    #随机选择num_Letter个字母
    UPLetter = [random.choice(string.ascii_letters.upper()) for i in range(num_UPLetter)]
    LOWLetter = [random.choice(string.ascii_letters.lower()) for i in range(num_LOWLetter)]
    #打乱这个组合
    Char = Num + Spe + UPLetter + LOWLetter
    random.shuffle(Char)
    #生成密码
    PWD = ''.join([i for i in Char])
    return PWD

length = int(input("Please input the length of the password:"))
print(GeneratePWD(length))
